<template>
  <div class="event_detail">
    <div class="event_tab">
      <div class="tab" @click="changeTab('1')" :style="{opacity: tabActive==='1'? '1' : '0.5'}">
        <div class="tab1_icon"/>
        <div class="tab_title">攻击事件</div>
        <div class="tab_bottom"></div>
      </div>
      <div class="divider"></div>
      <div class="tab" @click="changeTab('2')" :style="{opacity: tabActive==='2'? '1' : '0.5'}">
        <div class="tab2_icon"/>
        <div class="tab_title">异常工控</div>
        <div class="tab_bottom"></div>
      </div>
      <div class="divider"></div>
      <div class="tab" @click="changeTab('3')" :style="{opacity: tabActive==='3'? '1' : '0.5'}">
        <div class="tab3_icon"/>
        <div class="tab_title">异常网络</div>
        <div class="tab_bottom"></div>
      </div>
    </div>
<!--    <div class="table_content" v-if="tabActive==='3'">-->
<!--      <div class="line" v-for="(item, index) in assetDataList" :key="index">-->
<!--        <div class="firstLine">-->
<!--          <div class="point_div"></div>-->
<!--          <div class="lineTime">{{ item.createTime | formatDate }}</div>-->
<!--          <div class="data_name">{{ item.name }}</div>-->
<!--        </div>-->
<!--        <div class="secondLine">-->
<!--          <spread :msg="item.reason+item.suggest" :index="index"></spread>-->
<!--        </div>-->
<!--      </div>-->
<!--    </div>-->
    <div class="table_content">
      <div class="line" v-for="(item, index) in dataList" :key="index">
        <div class="firstLine">
          <div class="point_div"></div>
          <div class="lineTime">{{ item.createTime | formatDate }}</div>
        </div>
        <div class="secondLine">
          <spread :msg="item.description" :index="index"></spread>
        </div>
      </div>
    </div>
  </div>

</template>

<script>
import {
  riskAttackEvent,
  riskIndustrialEvent,
  abnormalAssets,
} from "@/api/bigSreen";
import { formatTime } from '@/utils'
import spread from '@/views/components/Spread'
export default {
  name: "event_detail",
  components: { spread },
  data() {
    return{
      tabActive: '1',
      tabImg: require("@/assets/img/bigScreen/event_tab1.svg"),
      dataList: [],
      assetDataList: [],
    }
  },
  filters: {
    formatDate: function (value) {
      if(value){
        return formatTime(new Date(value), 'yyyy-MM-dd HH:mm:ss')
      }
    }
  },
  created() {
    // this.getData();
  },

  mounted() {
    const f_width = document.querySelector('.event_detail').clientWidth
    const nodeList = document.querySelectorAll('.event_detail .tab')
    for (let i = 0; i < nodeList.length; i++) {
      let node = nodeList[i]
      node.style.width = (f_width / 3) + 'px'
    }
  },
  methods: {
    getData(){
      this.changeTab(this.tabActive);
    },
    changeTab(active){
      this.tabActive = active;
      if(active === '1'){
        this.riskAttackEvent();
      }else if(active === '2'){
        this.riskIndustrialEvent();
      }else if(active === '3'){
        this.abnormalAssets();
      }
    },
    async riskAttackEvent() {
      try {
        const res = await riskAttackEvent()
        this.dataList = res.data.data
      } catch (e) {
        console.log(e)
      }
    },
    async riskIndustrialEvent() {
      try {
        const res = await riskIndustrialEvent()
        this.dataList = res.data.data
      } catch (e) {
        console.log(e)
      }
    },
    async abnormalAssets() {
      try {
        const res = await abnormalAssets()
        // this.assetDataList = res.data.data
        this.dataList = res.data.data
      } catch (e) {
        console.log(e)
      }
    },
  }
}
</script>

<style scoped lang="scss">
.event_detail {
  position: relative;
  width: 100%;
  height: 100%;

  .event_tab {
    height: 5%;
    margin-top: 5px;
    background-size: 100% 100%;
    display: flex;

    .tab {
      height: 100%;
      position: relative;
      display: flex;
      justify-content: center;
      align-items: center;
      cursor: pointer;

      .tab_title {
        margin-left: 5px;
        font-size: 14px;
      }

      .tab_bottom {
        position: absolute;
        width:100%;
        height: 20px;
        bottom: -20px;
        background-image: url("~@/assets/img/bigScreen/tab_bottom.svg");
        background-repeat: no-repeat;
        background-position: 50% 0
      }
    }

    .divider {
      width: 0;
      height: 100%;
      border-left: 1px solid #234db5
    }

    .tab1_icon {
      width: 20px;
      height: 20px;
      background-image: url("~@/assets/img/bigScreen/icon_suyuan.svg");
      background-size: 100% 100%;
    }

    .tab2_icon {
      width: 20px;
      height: 20px;
      background-image: url("~@/assets/img/bigScreen/icon_caozuo.svg");
      background-size: 100% 100%;
    }

    .tab3_icon {
      width: 20px;
      height: 20px;
      background-image: url("~@/assets/img/bigScreen/icon_caozuo2.svg");
      background-size: 100% 100%;
    }
  }

  .table_content {
    margin-top: 6%;
    margin-left: 4%;
    width: 95%;
    height: 85%;
    overflow: auto;

    .line {
      width: 100%;
      height: auto;
      margin-bottom: 15px;

      .firstLine {
        width: 100%;
        height: 35%;
        display: flex;
        .point_div {
          width: 2%;
          height: 8px;
          margin-top: 1.2%;
          border-radius: 6px;
          background-color: #3e92ff;
          vertical-align: middle;
        }

        .lineTime {
          color: #3e92ff;
          margin-left: 1.5%;
          font-size: 12px;
        }

        .data_name {
          margin-left: 4%;
          font-size: 12px;
        }
      }

      .secondLine {
        color: #fff;
        margin-left: 3.5%;
        margin-top: 5px;
        width: 90%;
        height: auto;
        font-size: 12px;
      }
    }
  }
}
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
  background: transparent;
}
::-webkit-scrollbar-track {
  //-webitkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
  border-radius: 40px;
  background-color: transparent;
}
::-webkit-scrollbar-thumb {
  //-webitkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
  border-radius: 40px;
  background-color: #2686fe;
}
</style>
